package com.feifan.monthhelper.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.feifan.monthhelper.R;
import com.feifan.monthhelper.bean.MenstrualSperiodStatisticsBean;
import com.feifan.monthhelper.constant.Constant;
import com.feifan.monthhelper.ui.base.BaseActivity;
import com.feifan.monthhelper.utils.DateUtils;
import com.feifan.monthhelper.wedget.DoubleClickListener;
import com.feifan.monthhelper.wedget.view.CirclePieView2;

import butterknife.BindView;

/**
 * 月经周期统计详情
 */
public class MenstrualPeriodStatisticsActivity extends BaseActivity {

    @BindView(R.id.rl_title)
    View rlTitle;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_left_title)
    TextView tvLeftTitle;
    @BindView(R.id.tv_all_record)
    TextView tvAllRecord;
    @BindView(R.id.tv_menstrual_late)
    TextView tvMenstrualLate;
    @BindView(R.id.tv_menstrual_blood)
    TextView tvMenstrualBlood;
    @BindView(R.id.tv_menstrual_time)
    TextView tvMenstrualTime;
    @BindView(R.id.tv_keenly_feel)
    TextView tvKeenlyFeel;

    //经期统计记录
    MenstrualSperiodStatisticsBean menstrualSperiodStatisticsBean;
    @BindView(R.id.cpv_menstrual)
    CirclePieView2 cpvMenstrual;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View getTitleView() {
        return rlTitle;
    }

    @Override
    protected void initData() {
        menstrualSperiodStatisticsBean = getIntent().getParcelableExtra(Constant.ConstantName.LAST_MENSTRUAL_STATISTICS);
    }

    @Override
    protected void initView() {

        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        tvAllRecord.setOnClickListener(new DoubleClickListener() {
            @Override
            public void doOnClick(View view) {
                startActivity(new Intent(MenstrualPeriodStatisticsActivity.this, MenstrualRecordActivity.class));
            }
        });

        tvMenstrualTime.setText(String.format("%d天", menstrualSperiodStatisticsBean.getMenstrualPeriod()));
//        tvMenstrualLate.setText(String.format("%d天", menstrualSperiodStatisticsBean.getDelayDays()));
        if (menstrualSperiodStatisticsBean.getBloodLevel() == -1) {
            tvMenstrualBlood.setText("未记录");
        } else {
            tvMenstrualBlood.setText(String.format("%d级", menstrualSperiodStatisticsBean.getBloodLevel()));
        }
        if (menstrualSperiodStatisticsBean.getPainLevel() == -1) {
            tvKeenlyFeel.setText("未记录");
        } else {
            tvKeenlyFeel.setText(String.format("%d级", menstrualSperiodStatisticsBean.getPainLevel()));
        }
        String evaluation = getResources().getString(R.string.menstrual_normal);
        if (menstrualSperiodStatisticsBean.getState() == MenstrualSperiodStatisticsBean.MenstrualState.DELAY) {
            evaluation = getResources().getString(R.string.menstrual_late);
        } else if (menstrualSperiodStatisticsBean.getState() == MenstrualSperiodStatisticsBean.MenstrualState.AHEAD) {
            evaluation = getResources().getString(R.string.menstrual_ahead);
        }
        tvMenstrualLate.setText(evaluation);
        int score = 100 - menstrualSperiodStatisticsBean.getDelayDays() * 7;
        cpvMenstrual.setArcPercent(score < 0 ? 0 : score);
        tvLeftTitle.setText(DateUtils.init().dateToString(menstrualSperiodStatisticsBean.getStartDate(), DateUtils.DateStyle.MM_DD) + "-" + DateUtils.init().dateToString(menstrualSperiodStatisticsBean.getEndDate(), DateUtils.DateStyle.MM_DD));
    }

    @Override
    protected int setContentLayout() {
        return R.layout.activity_menstrual_period_statistics;
    }
}
